//
//  NewCellModel.m
//  GitBucket
//
//  Created by 3024 on 15/11/10.
//  Copyright © 2015年 ios25. All rights reserved.
//

#import "NewCellModel.h"

@implementation NewCellModel

+(instancetype)allocInitModel:(UIImage *)avatarImage typeImage:(UIImage *)typeImage textViewString:(NSString *)textViewString comment:(NSString *)comment date:(NSString *)date aNewdic:(NSDictionary *)aNewdic
{
    NewCellModel *model = [self new];
    //各种请求
    model.avatarImage = avatarImage;
    model.typeImage = typeImage;
    model.textViewString = textViewString;
    model.comment = comment;
    model.date =date;
    model.aNewdic = aNewdic;
    return model;
}

//归档时自动调用的方法
- (void)encodeWithCoder:(NSCoder *)aCoder{
    //aCoder是一个编码器,下面会用到它.它在这个方法被调用时会自动传入
    
    //如果父类也遵守NSCoder协议,则可能需要先调用父类方法
    //    [super encodeWithCoder:aCoder];
    
    //调用编码器的编码方法,对需要归档的数据进行编码
    //注意:被编码的对象必须也遵守NSCoding协议
    [aCoder encodeObject:self.avatarImage forKey:@"avatarImage"];
    [aCoder encodeObject:self.typeImage forKey:@"typeImage"];
    [aCoder encodeObject:self.textViewString forKey:@"textViewString"];
    [aCoder encodeObject:self.comment forKey:@"comment"];
    [aCoder encodeObject:self.date forKey:@"date"];
    [aCoder encodeObject:self.aNewdic forKey:@"aNewdic"];
}

//反归档时自动调用的方法
- (id)initWithCoder:(NSCoder *)aDecoder{
    //如果父类也遵守NSCoding协议可能需要先调用父类方法
    //    self = [super initWithCider:aDecider];
    
    //否则直接写
    self = [super init];
    
    if (self) {
        //对各个数据进行反归档,这里使用的是解码器
        _avatarImage = [aDecoder decodeObjectForKey:@"avatarImage"];
        _typeImage = [aDecoder decodeObjectForKey:@"typeImage"];
        _textViewString = [aDecoder decodeObjectForKey:@"textViewString"];
        _comment = [aDecoder decodeObjectForKey:@"comment"];
        _date = [aDecoder decodeObjectForKey:@"date"];
        _aNewdic = [aDecoder decodeObjectForKey:@"aNewdic"];
        
    }
    return self;
}
@end
